﻿#define _CRT_SECURE_NO_WARNINGS 1

#pragma once

#include <stdio.h>
#include <stdlib.h>//
#include <assert.h>//
#include <time.h>
#include <windows.h>

#define wall L'▭'////////
#define body L'●'
#define food L'◆'

#define KEY_PRESS(VK) ((GetAsyncKeyState(VK)&0x1) ? 1 : 0)

#define POS_X 24
#define POS_Y 5

//创建蛇段
typedef struct SnakeNode
{
	int x;
	int y;
	struct SnakeNode* next;/////
}SnakeNode,*pSnakeNode;

enum GAME_STATUS
{
	OK,
	KILL_BY_WALL,
	KILL_BY_SELF,
	END_NOMAL
};

enum DIRECTION
{
	UP = 1,
	DOWN,
	LEFT,
	RIGHT
};

//蛇状态
typedef struct Snake
{
	pSnakeNode _pSnake;
	pSnakeNode _pFood;
	enum DIRECTION _Dir;
	enum GAME_STATUS _Status;
	int _Score;//
	int _foodWeight;//
	int _SleepTime;//
}snake,*pSnake;

//游戏开始前的初始化
void GameStart(pSnake ps);
//游戏运⾏过程
void GameRun(pSnake ps);
//游戏结束
void GameEnd(pSnake ps);
//设置光标的坐标
void SetPos(short x, short y);
//欢迎界⾯
void WelcomeToGame();
//打印帮助信息
void PrintHelpInfo();
//创建地图
void CreatMap();
//初始化蛇
void InitSnake(pSnake ps);
//创建⻝物
void CreatFood(pSnake ps);
//暂停响应
void pause();
//吃⻝物
void EatFood(pSnakeNode psn, pSnake ps);
//不吃⻝物
void NoFood(pSnakeNode psn, pSnake ps);
//撞墙检测
int KillByWall(pSnake ps);
//撞⾃⾝检测
int KillBySelf(pSnake ps);
//蛇的移动
void SnakeMove(pSnake ps);
//游戏初始化
void GameStart(pSnake ps);
//游戏运⾏
void GameRun(pSnake ps);
//游戏结束
void GameEnd(pSnake ps);
//打印
void Printf(pSnakeNode cur);